package com.catazy.wanandroid.common_base.ext

import com.catazy.wanandroid.common_base.BuildConfig
import com.orhanobut.logger.Logger

/**
 * 作者: Tao
 * 日期: 2024/4/10
 * 时间: 11:17
 * 描述: Log 扩展类
 */

private const val VERBOSE = 1
private const val DEBUG = 2
private const val INFO = 3
private const val WARN = 4
private const val ERROR = 5

private val level = if (BuildConfig.DEBUG) VERBOSE else WARN

fun logV(msg: String?) {
    if (level <= VERBOSE) {
        Logger.v(msg.toString())
    }
}

fun logD(tag: String, msg: String?) {
    if (level <= DEBUG) {
        Logger.d(msg.toString())
    }
}

fun logD(tag: String, obj: Any?) {
    if (level <= DEBUG) {
        Logger.d(obj)
    }
}

fun logD(obj: Any?) {
    if (level <= DEBUG) {
        Logger.d(obj)
    }
}

fun logI(tag: String, msg: String?) {
    if (level <= INFO) {
        Logger.i(msg.toString())
    }
}

fun logI(msg: String?) {
    if (level <= INFO) {
        Logger.i(msg.toString())
    }
}

fun logW(tag: String, msg: String?, tr: Throwable? = null) {
    if (level <= WARN) {
        if (tr == null) {
            Logger.w(msg.toString())
        } else {
            Logger.w(msg.toString(), tr)
        }
    }
}

fun logW(msg: String?) {
    if (level <= WARN) {
        Logger.w(msg.toString())
    }
}

fun logE(tag: String, msg: String?, tr: Throwable? = null) {
    if (level <= ERROR) {
        if (tr == null){
            Logger.e(msg.toString())
        }else {
            Logger.e(msg.toString(), tr)
        }
    }
}

fun logE(msg: String?) {
    if (level <= ERROR) {
        Logger.e(msg.toString())
    }
}